﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ColorLine : MonoBehaviour
{
    public Image first;
    public int segment = 20;
    [ContextMenu("Generate")]
    void Generate()
    {
        Generate(Vector3.one.to0YZ(), Vector3.right, "HueLine", 0);
        Generate(Vector3.one.toX0Z(), Vector3.up, "SaturationLine", 1.1f);
        Generate(Vector3.zero, Vector3.forward, "BrightLine", 2.2f);
    }
    void Generate(Vector3 baseV, Vector3 hsb, string name, float yPosMulty)
    {
        first.gameObject.SetActive(true);
        var factor = 1f / segment;
        GameObject go = new GameObject(name);
        go.SetParent(transform);
        go.transform.position = first.transform.parent.position;
        for (int i = 0; i < segment; i++)
        {
            var n = Instantiate(first);
            n.transform.SetParent(go);
            var rt = first.rectTransform;
            n.transform.position = first.transform.position;
            n.rectTransform.anchoredPosition += new Vector2(rt.sizeDelta.x * i, rt.sizeDelta.y * yPosMulty);
            var v = baseV + hsb * i * factor;
            n.color = Color.HSVToRGB(v.x, v.y, v.z);
        }
        first.gameObject.SetActive(false);
    }
}
